#结点
class Node:
    def __init__(self,data):
        self.data = data
        self.next = None
        
#链栈
class LinkStack:
    def __init__(self):
        #头指针
        self.top = None
        #链栈长度
        self.length = 0
    #进栈
    def push(self):
        #获取新结点
        data = input("请输入结点数据：")
        newNode = Node(data)
        newNode.next = self.top
        #头指针指向新结点
        self.top = newNode
        #链栈长度+1
        self.length += 1
    #出栈
    def pop(self):
        #判断栈是否为空
        curNode = self.top
        if not curNode:
            return
        self.top = curNode.next
        self.length -= 1
    #遍历
    def outline(self):
        #判断栈是否为空
        curNode = self.top
        if not curNode:
            return
        print("===========栈的元素===========")
        while(curNode):
            print(curNode.data)
            curNode = curNode.next
        print("=============================")
        

if __name__ == "__main__":   
    while 1:
        print("1-初始链栈   2-元素入栈")
        print("3-元素出栈   4-退出程序")
        command=  input("请输入您的指令：")
        if(command=="1"):
            lSt = LinkStack()
            print("初始化成功")
        elif(command=="2"):
            lSt.push()
            lSt.outline()
        elif(command=="3"):
            lSt.pop()
            lSt.outline()
        else:
            break